from django.db import models


class Author(models.Model):
    name = models.CharField(max_length=32, unique=True, null=False, verbose_name='姓名')
    age = models.IntegerField(verbose_name='年龄')
    gender_choices = [
        (1, 'male'),
        (2, 'female'),
        (3, 'other')
    ]
    gender = models.IntegerField(choices=gender_choices, default=1, verbose_name='性别')
    author_login = models.OneToOneField(to='AuthorLogin', on_delete=models.CASCADE, verbose_name='作者登录表',
                                        null=True)
    author_detail = models.OneToOneField(to='AuthorDetail', on_delete=models.CASCADE, verbose_name='详细信息')
    publish = models.ForeignKey(to='publish.Publish', on_delete=models.CASCADE, verbose_name='所属出版社', null=True)

    def __str__(self):
        return f"{self.name} 作者对象"

    class Meta():
        db_table = "author"
        verbose_name_plural = "作者表"


class AuthorDetail(models.Model):
    email = models.EmailField()
    addr = models.CharField(max_length=255)
    desc = models.TextField()

    class Meta():
        db_table = "author_detail"
        verbose_name_plural = "作者详情表"


class AuthorLogin(models.Model):
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=255)

    class Meta():
        db_table = 'author_login'
        verbose_name_plural = '作者登录信息'
